package com.test.javafaq_search.repository;

import com.test.javafaq_search.vo.QuestionVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface QuestionRepository extends ElasticsearchRepository<QuestionVo,Integer> {

    //查询 项目搜索功能的方法
    @Query("{\n" +
            "    \"bool\": {\n" +
            "      \"must\": [{\n" +
            "        \"bool\": {\n" +
            "         \"should\": [\n" +
            "           {\"match\": {\"title\": \"?0\"}},\n" +
            "           {\"match\": {\"content\": \"?1\"}}\n" +
            "         ]}\n" +
            "        },{\n" +
            "        \"bool\": {\n" +
            "          \"should\": [\n" +
            "            {\"term\": {\"publicStatus\": 1}},\n" +
            "            {\"term\": {\"userId\": ?2}}\n" +
            "          ]}\n" +
            "      }]\n" +
            "    }\n" +
            "}")
    public Page<QuestionVo> queryAllByParams(String title, String content, Integer userId, Pageable pageable);
}
